package com.kaigejava.juc.pool.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author kaigejava
 * callable接口演示
 */
public class CallableDemo {
    public static void main(String[] args) throws  Exception {
        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread3());
        Thread t1 = new Thread(futureTask,"第三种获取线程方式");
        Thread t2 = new Thread(futureTask,"第三种获取线程方式2222");
        t1.start();
        t2.start();
        System.out.println("获取线程返回值为："+futureTask.get());
    }
}
/**
 * 第三种：实现callable接口
 */
class MyThread3 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName() +"===进入Callable接口的call方法了。。。");
        return 1024;
    }
}


/**
 * 方法一：继承Thread类
 */
class MyThread extends  Thread{

}

/**
 * 方法二：实现runnable接口
 */
class MyRunnable implements  Runnable{
    @Override
    public void run() {

    }
}

